<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2018/4/2
  Time: 20:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>user add</title>
    <style type="text/css">
        table {
            border: 1px solid #000;
            border-collapse: collapse;
        }

        td, th {
            border: 1px solid #000;
            padding: 10px;
        }
    </style>
</head>
<body>
<a href="userList.jsp">返回用户列表</a></br>

<form method="post" action="">
    用户名：<input type="text" name="name"/></br>
    密码：<input type="text" name="password"/></br>
    <input type="submit" value="保存"/>

</form>

<%
    request.setCharacterEncoding("UTF-8");
    String  id=request.getParameter("id");
    String name=request.getParameter("name");
    String password=request.getParameter("password");

    Connection connection=null;
    PreparedStatement statement=null;


    String sql="insert INTO user VALUES (?,?,?)";

    Class.forName("com.mysql.jdbc.Driver");

    connection= DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC",
            "root",
            "121212");
    statement=connection.prepareStatement(sql);

    statement.setString(1, id);
    statement.setString(2,name);
    statement.setString(3,password);
    int result=statement.executeUpdate();
    String hint="添加失败！";
    if (result==1){
        hint="添加成功！";
    }

    statement.close();
    connection.close();


%>


</body>
</html>
